#include <bits/stdc++.h>
// Tag: dynamic programming, bit manipulation
using namespace std;

int C, N;
int dp[1 << 18];      // Maximum possible size for C <= 18
int o[100001];        // Stores the bitmask for each team
string s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> C >> N;
    int t = 1 << C;   // Total number of possible bitmasks

    // Initialize dp array to a large value (infinite distance)
    for (int i = 0; i < t; i++)
        dp[i] = 1e9;

    // Read and process each team's string to create bitmasks
    for (int i = 1; i <= N; i++)
    {
        cin >> s;
        o[i] = 0;     // Reset o[i] for each team
        for (int j = 0; j < C; j++)
        {
            if (s[j] == 'H')
                o[i] |= (1 << j); // Set bit j if character is 'H'
        }
        dp[o[i]] = 0; // Distance to self is 0
    }

    // Dynamic Programming to compute minimum flips to reach each bitmask
    for (int i = 0; i < C; i++)            // For each bit position
    {
        for (int j = 0; j < t; j++)        // For each possible bitmask
        {
            int next_mask = j ^ (1 << i);  // Flip the i-th bit
            dp[next_mask] = min(dp[next_mask], dp[j] + 1);
        }
    }

    // Output the maximum difference for each team
    for (int i = 1; i <= N; i++)
        cout << C - dp[(t - 1) ^ o[i]] << endl; // Inverse the bitmask and compute

    return 0;
}
